<?php

namespace app\admin\Lib;
use think\Controller;
class Detail{
	//车辆参数处理


	//处理
	Static public function details($arr,$name,$title,$remarks){
				$arrlist = array();
			foreach ($arr as $key => $value) {
						$arrlist[] = [
									$name =>$value['name'],
									$title =>$value['title'],
									$remarks =>$value['remarks'],
						];

			}
			return $arrlist;
		}

	//添加数据处理
	Static public function detaillist($commercial_insurance_name,$commercial_insurance_title,$remarks_ad,$name,$title,$remarks){
		foreach ($commercial_insurance_name as $key => $value){
						 $arrname[] = [
										$name =>$value,
										$title =>$commercial_insurance_title[$key],
										$remarks =>$remarks_ad[$key],

						 ];
		}
			return json_encode($arrname);
	}

	// 添加数据处理
	Static public function detaillist1($commercial_insurance_name,$commercial_insurance_title,$name,$title){
		foreach ($commercial_insurance_name as $key => $value){
						 $arrname[] = [
										$name =>$value,
										$title =>$commercial_insurance_title[$key],


						 ];
		}
			return json_encode($arrname);
	}
	//处理配置信息未json
	Static public function detailxianxi($data){
		$arr["result"] =  [
		    	"基本参数" => [
			      "manufacturers" =>  $data['manufacturers'],
			      "level" =>  $data['level'],
			      "engine" =>  $data['engine'],
			      "gearbox" =>  $data['gearbox'],
			      "longHighWith" =>  $data['longHighWith'],
			      "bodyStructure" =>  $data['bodyStructure'],
			      "maximumSpeed" =>  $data['maximumSpeed'],
			      "officialAcceleration" =>  $data['officialAcceleration'],
			      "measuredAcceleration" =>  $data['measuredAcceleration'],
			      "measuredBrake" =>  $data['measuredBrake'],
			      "measuredFuelConsumption" => $data['measuredFuelConsumption'],
			      "averageConsumptionOfCertification" =>  $data['averageConsumptionOfCertification'],
			      "ministryOfIntegratedFuelConsumption" => $data['ministryOfIntegratedFuelConsumption'],
			      "measuredGroundClearance" =>  $data['measuredGroundClearance'],
			      "vehicleQuality" => $data['vehicleQuality'],
		    ],
		    "车身" => [
		      "length" => $data['length'],
		      "width" =>  $data['width'],
		      "height" => $data['height'],
		      "wheelbase" =>  $data['wheelbase'],
		      "frontTrack" => $data['frontTrack'],
		      "rearWheel" =>  $data['rearWheel'],
		      "minnumGroundClearance" =>  $data['minnumGroundClearance'],
		      "kerbMass" =>  $data['kerbMass'],
		      "bodyStructure" =>  $data['bodyStructure'],
		      "numberOfDoors" =>  $data['numberOfDoors'],
		      "numberOfSeats" =>  $data['numberOfSeats'],
		      "mailVolume" =>  $data['mailVolume'],
		      "compartmentVolume" =>  $data['compartmentVolume'],
		    ],
		    "发动机" =>  [
		      "model" => $data['model'],
		      "displacement" => $data['displacement'],
		      "intakeForm" => $data['intakeForm'],
		      "cylinderExhaustForm" => $data['cylinderExhaustForm'],
		      "cylinders" => $data['cylinders'],
		      "valvePerCylinder" => $data['valvePerCylinder'],
		      "compressionRatio" => $data['compressionRatio'],
		      "gasDistrbutionMechanism" => $data['gasDistrbutionMechanism'],
		      "cylinderBy" => $data['cylinderBy'],
		      "trip" => $data['trip'],
		      "maxHorsepower" => $data['maxHorsepower'],
		      "maxPower" => $data['maxPower'],
		      "maxPowerSpeed" => $data['maxPowerSpeed'],
		      "maxTorque" =>$data['maxTorque'],
		      "maxTorqueSpeed" => $data['maxTorqueSpeed'],
		      "specialTechnology" => $data['specialTechnology'],
		      "fuelForm" => $data['fuelForm'],
		      "fuel" => $data['fuel'],
		      "fuleWay" => $data['fuleWay'],
		      "cylinderHeadMeterial" => $data['cylinderHeadMeterial'],
		      "cylinderMaterial" => $data['cylinderMaterial'],
		      "environmentalProtection" => $data['environmentalProtection'],
		    ],
		    "变速箱" =>  [
		      "abbreviation" => $data['abbreviation'],
		      "grarNum" => $data['grarNum'],
		      "type" =>  $data['type'],
		    ],
		    "底盘转向" =>  [
		      "drivingMethod" => $data['drivingMethod'],
		      "fourWheelDriveForm" => $data['fourWheelDriveForm'],
		      // "centralDifferentialStructure" => $data['centralDifferentialStructure'],
		      "frontSuspensionType" => $data['frontSuspensionType'],
		      "SuspensionType" => $data['SuspensionType'],
		      "powerType" => $data['powerType'],
		      "bodyStructure" => $data['bodyStructure'],
		    ],
		    "车轮制动" => [
		      "frontBrakeType" =>$data['frontBrakeType'],
		      "brakeType" => $data['brakeType'],
		      "parkingBrakeType" => $data['parkingBrakeType'],
		      "frontTyreSpecifications" => $data['frontTyreSpecifications'],
		      "typreSpecifications" => $data['typreSpecifications'],
		      "spareTrieSpecifications" => $data['spareTrieSpecifications'],
		    ],
		    "安全装备" => [
		      "lordDeputyDirversSeatAirbag" => $data['lordDeputyDirversSeatAirbag'],
		      "sagetyBeltPrompt" => $data['sagetyBeltPrompt'],
		      "frontAndRearSideAirbags" => $data['frontAndRearSideAirbags'],
		      "beforeAndAffterTheHeadAirbag" => $data['beforeAndAffterTheHeadAirbag'],
		      "kneeAirbag" => $data['kneeAirbag'],
		      "pressureMonitoringDevice" => $data['pressureMonitoringDevice'],
		      "zeroPressureContinuedTravel" => $data['zeroPressureContinuedTravel'],
		      "childSeatInterface" => $data['childSeatInterface'],
		      "engineElectronicAntitheft" => $data['engineElectronicAntitheft'],
		      "controlLock" => $data['controlLock'],
		      "RmeoteKey" => $data['RmeoteKey'],
		      "keylessStartSystem" => $data['keylessStartSystem'],
		      "keylessEntrySystem" => $data['keylessEntrySystem'],
		    ],
		    "操控配置" => [
		      "ABS" => $data['ABS'],
		      "brakingForceDistribution" => $data['brakingForceDistribution'],
		      "braleAssist" => $data['braleAssist'],
		      "tractionControl" => $data['tractionControl'],
		      "stabilityControl" => $data['stabilityControl'],
		      "upslopeAuxiliary" => $data['upslopeAuxiliary'],
		      "automaticParking" => $data['automaticParking'],
		      "steepSlopeSlowlyDescending" => $data['steepSlopeSlowlyDescending'],
		      "variableSuspension" => $data['variableSuspension'],
		      "frontAxleLimitedSlip" => $data['frontAxleLimitedSlip'],
		      // "centralDifferential" => $data['centralDifferential'],
		      "axleLimitedSlip" => $data['axleLimitedSlip'],
		      "differentialLocking" => $data['differentialLocking'],
		      // "DifferetialMechanism" => $data['DifferetialMechanism'],
		    ],
		    "外部配置" =>  [
		      "electricSkylight" => $data['electricSkylight'],
		      "panoramicSunroof" => $data['panoramicSunroof'],
		      "appearancePackage" => $data['appearancePackage'],
		      "aluminumAlloyWheels" => $data['aluminumAlloyWheels'],
		      "electricSuctionDoor" => $data['electricSuctionDoor'],
		      "slideDoor" => $data['slideDoor'],
		      "electricTrunk" =>$data['electricTrunk'],
		    ],
		    "内部配置" =>  [
		      "leatherSteeringWheel" => $data['leatherSteeringWheel'],
		      "steeringWheelAdjustment" => $data['steeringWheelAdjustment'],
		      "steeringWheelOfElectricControl" => $data['steeringWheelOfElectricControl'],
		      "multifunctionSteeringWheel" => $data['multifunctionSteeringWheel'],
		      "steeringWheelShift" => $data['steeringWheelShift'],
		      "steeringWheelHeating" => $data['steeringWheelHeating'],
		      "cruiseControl" => $data['cruiseControl'],
		      "parkingRadar" => $data['parkingRadar'],
		      "reverseVideoPhotography" => $data['reverseVideoPhotography'],
		      "drivingComputerDispaly" => $data['drivingComputerDispaly'],
		      "HUD" => $data['HUD'],
		    ],
		    "座椅配置" =>  [
		      "genuineLeather" => $data['genuineLeather'],
		      "movementStyle" => $data['movementStyle'],
		      "heightAdjustment" => $data['heightAdjustment'],
		      "lumbarSupport" => $data['lumbarSupport'],
		      "shoulderSupport" => $data['shoulderSupport'],
		      "driverSeatElectricAdjustment" => $data['driverSeatElectricAdjustment'],
		      "SecondRowOfBackrestAngleAdjustment" => $data['SecondRowOfBackrestAngleAdjustment'],
		      // "secondSeatMove" => $data['secondSeatMove'],
		      "RearSeatElectricAdjustment" => $data['RearSeatElectricAdjustment'],
		      "electricSeatMemory" => $data['electricSeatMemory'],
		      "Heating" => $data['Heating'],
		      "ventilation" => $data['ventilation'],
		      "massage" => $data['massage'],
		      "backDowmMode" => $data['backDowmMode'],
		      "ThirdRowSeat"=> $data['ThirdRowSeat'],
		      "handrail" => $data['handrail'],
		      // "rearGlassFrame" => $data['rearGlassFrame'],
		    ],
		    "多媒体配置" =>  [
		      "GPS" => $data['GPS'],
		      // "orientationOfInteraction" => $data['orientationOfInteraction'],
		      "consoleScreen" => $data['consoleScreen'],
		      "hardDrive" => $data['hardDrive'],
		      "bluetoothPhone" => $data['bluetoothPhone'],
		      // "TV" => $data['TV'],
		      "rearLcdScreen" => $data['rearLcdScreen'],
		      "externalSoundSource" => $data['externalSoundSource'],
		      "cd" => $data['cd'],
		      "multimediaSystem" => $data['multimediaSystem'],
		      "speakerBrand" => $data['speakerBrand'],
		      "loundspeakersNum" => $data['loundspeakersNum'],
		    ],
		    "灯光配置" =>  [
		      "gangGasHeadlight" => $data['gangGasHeadlight'],
		      "LED" => $data['LED'],
		      "daytimeWalkLamp" => $data['daytimeWalkLamp'],
		      "automaticHeadlights" => $data['automaticHeadlights'],
		      "steeringSuxiliaryLamp" => $data['steeringSuxiliaryLamp'],
		      "steeringHeadlamp" => $data['steeringHeadlamp'],
		      "frontFogLamp" => $data['frontFogLamp'],
		      "headlightAdjusting" => $data['headlightAdjusting'],
		      "headlightCleaning" => $data['headlightCleaning'],
		      // "atmosphereLamp" => $data['atmosphereLamp'],
		    ],
		    "玻璃后视镜" => [
		      "electricWindow" =>$data['electricWindow'],
		      "preventClampsHand" => $data['preventClampsHand'],
		      "ultravioletRays" => $data['ultravioletRays'],
		      "mirrorElectricAdiustment" => $data['mirrorElectricAdiustment'],
		      "rearviewMirrorHeating" => $data['rearviewMirrorHeating'],
		      // "antiGtlare" => $data['antiGtlare'],
		      "fold" => $data['fold'],
		      "memory" => $data['memory'],
		      "yangCurtain" => $data['yangCurtain'],
		      "ceZheCurtain" => $data['ceZheCurtain'],
		      "privacyglass" => $data['privacyglass'],
		      "cosmeticMirror" => $data['cosmeticMirror'],
		      "rearWiper" => $data['rearWiper'],
		      "sensingWipers" => $data['sensingWipers'],
		    ],
		    "空调冰箱" =>  [
		      // "controlMethod" => $data['controlMethod'],
		      // "rearAirConditioning" => $data['rearAirConditioning'],
		      // "rearSeatVents" => $data['rearSeatVents'],
		      // "temperatureCXontrol" => $data['temperatureCXontrol'],
		      // "airConditioning" => $data['airConditioning'],
		      // "regrigerator" => $data['regrigerator'],
		    ],
		    "高科技配置" => [
		      "automaticParking" => $data['automaticParking'],
		      "engineStartStop" => $data['engineStartStop'],
		      "auxiliary" => $data['auxiliary'],
		      "laneDepartureWarning" => $data['laneDepartureWarning'],
		      "activesafety" => $data['activesafety'],
		      "activeSteering" => $data['activeSteering'],
		      "nightVisionSystem" => $data['nightVisionSystem'],
		      // "lcdScreen" => $data['lcdScreen'],
		      "adaptiveCruiseControl" => $data['adaptiveCruiseControl'],
		      "panoramicCamera" => $data['panoramicCamera'],
		    ],
		  ];

		return json_encode($arr);
	 }
	//处理数据月供
	Static public function yuegong($arr){
		// repayments还款年限(json)
		// necessary_charges必要收费(json)
		// commercial_insurance商业保险（json）
		  $shoufu = json_decode($arr['repayments'],true);//还款年限(json)
			$yuegong = json_decode($arr['necessary_charges'],true);//必要收费(json)
			$insurance = json_decode($arr['commercial_insurance'],true);//商业保险（json）
			$dow_payments = json_decode($arr['dow_payments'],true);//首付(json)

			$biyuans = 0;
			//必要花费相加
			foreach ($yuegong as $key => $value) {
						$biyuans += $value['necessary_charges_title'];
			}
			//商业保险(json)
			$insuranced = explode('|',$insurance[0]['commercial_insurance_title']);
			foreach ($insuranced as $k => $v) {
					$wan = explode(',',$v);
						$arrs[$k] = $wan;
					}
			// 玻璃单独破碎险(元)拆分
				$boli = explode('|',$insurance[3]['commercial_insurance_title']);
			foreach ($boli as $ks => $vs) {
					$wans = explode(',',$vs);
					$bolia[$ks] = $wans;
			}
			// 车身刮痕险(元)拆分
				$cheshen = explode('|',$insurance[8]['commercial_insurance_title']);
			foreach ($cheshen as $ksd => $vsd) {
					$wansd = explode(',',$vsd);
					$cheshens[$ksd] = $wansd;
			}
			// $arrd['repayments'] = $shoufu;
			$arrd['necessary_charges'] = $yuegong;
			$arrd['commercial_insurance'] = $insurance;
			//必要花费相加金额
			$arrd['cost'] = $biyuans;
			// 商业保险(json)拆分
			$arrd['necessary_charges_titles'] = $arrs;
			// 玻璃单独破碎险(元)拆分
			$arrd['bolis'] = $bolia;
			// 车身刮痕险(元)拆分
			$arrd['cheshen'] = $cheshens;

			//月供算法
			// 月供=[(指导价+必须花费上牌保险等)-（首付比例*指导价）]*年份利息/还款期数
			//
			// 首付=指导价*首付比例+必要花费+商业保险
			//
			// 必要花费=购置税+上牌费+车船税+交强险

			$disanze = $arrs['0']['1'];//第一个数组第三者保险金额¥
			$bolid = $bolia['0']['1'];//第一个玻璃单独破碎险金额¥

			$shanye = 0;
			foreach ($insurance as $kd => $vd) {
					if (is_numeric($vd['commercial_insurance_title'])) {
						$shanye+=$vd['commercial_insurance_title'];//统计商业保险金额¥
					}
			}
			// dump($shanye);
			$guidance_price = $arr['guidance_price'];//指导价
			//年限//默认最高
			$nianxian = array_pop($shoufu);
			// 月供=[(指导价+必须花费上牌保险等)-（首付比例*指导价）]*年份利息/还款期数
			//上牌保险+必要花费
			$by =$disanze+$bolid+$shanye;
			$y =$guidance_price+$biyuans+$by;//指导价+必须花费上牌保险等
			$d =$dow_payments[0]['dow_payments_title']/100*$guidance_price;//首付比例*指导价
			$c = $y-$d;
			$q =$c*$nianxian['repayments_remarks'];
			$f = $c + $q;
			$z = round($f/($nianxian['repayments_title']*12),2); //结算最低月供
			$arrd['yuegong'] = $z;//月供
			//首付
			$aa = $guidance_price * ($dow_payments[0]['dow_payments_title']/100);
			$bb = round(($aa+$biyuans+$by),2);//商业保险金额
			$arrd['shoufus'] = $bb;//首付
			$arrd['nianfen'] = $nianxian;//年份
			$arrd['shoufu'] = $dow_payments[0]['dow_payments_title'];//年份
			return $arrd;





	}
		//商业保险统计
	Static public function yuegongs(){




	}




}



















//
